package com.woniu.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;
    //请求成功的常量
    public static final Result<Void> SUCCESS = new Result<>(200, "success", null);
    //请求失败，服务器报错的常量
    public static final Result<Void> FAIL = new Result<>(500, "fail", null);
    //请求成功无数据返回的方法
    public static Result<Void> ok(){
        return new Result<>(200, "success" ,null);
    }
    //请求成功返回对象
    public static <T> Result<T> ok(T data){
        return new Result<>(200, "success" ,data);
    }
    //请求成功返回String
    public static <T> Result<T> ok(String msg){
        return new Result<>(200, msg , null);
    }
    //请求失败返回String
    public static <T> Result<T> fail(String msg){
        return new Result<>(401, msg , null);
    }
    //请求失败返回String
    public static <T> Result<String> error(String msg){
        return new Result<>(500, msg, "服务器正忙，稍后重试");
    }
}
